#!/bin/sh

get_all_disks()
{
	# get all the disks with partitions as well
	local DISKS=$(cat /proc/partitions | awk '{ if ( NR >= 3 ) { print "/dev/"$4 } }')
	#remove all the partitions and only keep the disks
	local DISKS_TMP=$DISKS
	local disk
	for disk in $DISKS
	do
		#disk=$(echo $disk | sed 's/\//\\\//g')
		DISKS_TMP=$(echo $DISKS_TMP | sed "s|$disk[^ ]\+\b||g")
	done
	ALL_DISKS=$DISKS_TMP
}


# get the disk name from its partition name
# agrument: 
#       arg1 - partition name
#       use global variable - ALL_DISKS
get_disk_from_partition()
{
    get_all_disks
    local disk
    for disk in $ALL_DISKS
    do
        local tmpvar=$(echo $1 | sed "s|^$disk||g")
        if [ "$tmpvar" != $1 ]
        then
            echo $disk
            return
        fi
    done    
}

result=$(get_disk_from_partition "/dev/sda1")
echo $result
result=$(get_disk_from_partition "/dev/sdb1")
if [ -z "$result" ]; then
echo "empty"
fi


